// 滑动窗口；时间复杂度O(n + m);空间复杂度O(n)

class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int sLen = s.size(), pLen = p.size();
        if (sLen < pLen) return {};
        vector<int> sNums(26, 0);
        vector<int> pNums(26, 0);
        for (auto c: p) {
            pNums[c - 'a']++;
        }
        vector<int> ret;
        int l = 0, r = pLen - 1;
        for (int i = 0; i < pLen; i++) {
            sNums[s[i] - 'a']++;
        }
        while (r < sLen) {
            if (sNums == pNums) ret.emplace_back(l);
            if (r == sLen - 1) break;
            sNums[s[l] - 'a']--;
            sNums[s[r + 1] - 'a']++;
            r++;
            l++;
        }
        return ret;
    }
};